#include "udp_socket.hpp"

#define CHECK_RET(q) if((q)==false){return -1;}
int main(int argc, char* argv[])
{
    if(argc != 3){
      std::cout<<" Usage: ./udp_client 192.168.197.128 9000\n";
      std::cout<<"Server Address!!!\n";
    }
    std::string srv_ip =argv[1];
    int srv_port = std::stoi(argv[2]);

    UdpSocket sock;
    //1. 创建套接字
    CHECK_RET(sock.Socket());
    //2. 绑定地址信息（不推荐）
    while(1) {
        //3. 发送数据
        std::string buf;
        std::cout << "client say: ";
        fflush(stdout);
        std::cin >> buf;
        CHECK_RET(sock.Send(buf, srv_ip, srv_port));
        //4. 接收数据
        buf.clear();
        CHECK_RET(sock.Recv(&buf));
        std::cout << "server say: " << buf << std::endl;
    }
    //5. 关闭套接字
    CHECK_RET(sock.Close());
    return 0;
}

